import Vue from 'vue'
import Vuex from 'vuex'
import { getUserInfoByPhone } from '@/api/index.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: {
      name: '刺客567',
      sex: '男',
      phone: '13333333333',
      zone: '湖南省长沙市岳麓区',
      address: '湖南省长沙市岳麓区东方红大厦'
    },
    userInfoMD: {} // 用户信息
  },

  mutations: {
    updateUserInfo (state, data) {
      state.userInfoMD = data
    }
  },
  actions: {
    // 获取用户信息
    async getUserInfo (context, phone) {
      const { data } = await getUserInfoByPhone(phone)
      context.commit('updateUserInfo', data[0])
    }
  },
  getters: {
    userInfoMD: state => state.userInfoMD
  }
})
